package com.kob.backend.controller.user;

import com.kob.backend.mapper.UserMapper;
import com.kob.backend.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class UserController {

    @Autowired
    private UserMapper userMapper;
     @GetMapping("/user/all/")
    public List<User> getAll(){
         return userMapper.selectList(null);
     }

     @GetMapping("/user/add/{userId}/{username}/{password}")
    public String addUser(
            @PathVariable int userId,
            @PathVariable String username,
            @PathVariable String password){
         PasswordEncoder passwordEncoder=new BCryptPasswordEncoder();
         String encodedPassword=passwordEncoder.encode(password);
         User user=new User(userId,username,encodedPassword,null);
         userMapper.insert(user);
         return "Add User Successfully";

    }


}
